x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 16 Sep 2015 14:37:12 +0000 (10:37 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 29 Apr 2016 07:58:32 +0000 (03:58 -0400)
commitffcd7c069881219d4e60f3e5d7f12f1df44c9353
treedaf07f9b3b3d5f14e98f876682a3e0a65f86c7aa
parent29f4ab0b0a4ff62589af35b7cbc2334e1d9acdcd
x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.

This change demonstrates how to generate an xSplice ELF payload.

The idea here is that we want to patch in the hypervisor
the 'xen_version_extra' function with an function that will
return 'Hello World'. The 'xl info | grep extraversion'
will reflect the new value after the patching.

To generate this ELF payload file we need:
 - C code of the new code (xen_hello_world_func.c).
 - C code generating the .xsplice.funcs structure
   (xen_hello_world.c)
 - The address of the old code (xen_extra_version). We
   retrieve it by  using 'nm --defined' on xen-syms.
 - The size of the new and old code for which we use
   nm --defined -S on our code and xen-syms respectively.

There are two C files and one header files generated
during build. One could make this one C file if the
size of the newly patched function size was known in
advance (or an random value was choosen).

There is also a strict order of compiling:
 1) xen_hello_world_func.c
 2) config.h - extract the size of the new function,
    the old function and the old function address.
 3) xen_hello_world.c - which contains the .xsplice.funcs
    structure.
 4) Link the object files in an xen_hello_world.xsplice file.

The use-case is simple:

$xen-xsplice load /usr/lib/debug/xen_hello_world.xsplice
$xen-xsplice list
 ID                                     | status
----------------------------------------+------------
xen_hello_world                           APPLIED
$xl info | grep extra
xen_extra              : Hello World
$xen-xsplice revert xen_hello_world
Performing revert: completed
$xen-xsplice unload xen_hello_world
Performing unload: completed
$xl info | grep extra
xen_extra              : -unstable

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com> [ARM]
Acked-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
.gitignore
docs/misc/xsplice.markdown
xen/Makefile
xen/arch/arm/Makefile
xen/arch/x86/Makefile
xen/arch/x86/test/Makefile [new file with mode: 0644]
xen/arch/x86/test/xen_hello_world.c [new file with mode: 0644]
xen/arch/x86/test/xen_hello_world_func.c [new file with mode: 0644]